package Recommendation;

import User.User;

public class Euclidean implements Recommendation
{
	private double[] ratings1;
	private double[] ratings2;
	
	public Euclidean(User user1, User user2)
	{
		ratings1 = user1.getRatings(user1.getSharedIds(user2));
		ratings2 = user2.getRatings(user1.getSharedIds(user2));
	}
	
	public Euclidean(double[] ratings1, double[] ratings2)
	{
		this.ratings1 = ratings1;
		this.ratings2 = ratings2;
	}
	
	public double calc()
	{
		return 1 / (1 + Math.sqrt(root()));
	}
	
	public double root()
	{
		double root = 0;
		for (int i = 0; i < ratings1.length; i++)
		{
			root += Math.pow(ratings2[i] - ratings1[i], 2);
		}
		
		return root;
	}
	
	public double extend(double value)
	{
		double root = 0;
		if (value != 0)
		{
			root = reverse(value);
		}
		
		return 1 / (1 + Math.sqrt(root + root()));
	}
	
	public double reverse(double value)
	{
		return Math.pow(1 / value - 1, 2);
	}
}
